﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.BlackApart.Business.ApartmentServices {
    public class DefaultAdditionalServicePrice {

        #region Fields

        private readonly IAdditionalService service;
        private readonly int dayCounts;
        private readonly int peopleCounts;

        #endregion

        #region Properties

        public double Price { get; private set; }

        #endregion

        #region Constructors

        public DefaultAdditionalServicePrice(IAdditionalService service, DateTime fromDate, DateTime toDate, int peopleCounts)
            : this(service, (int)(toDate.Date - fromDate.Date).TotalDays, peopleCounts) {
        }

        public DefaultAdditionalServicePrice(IAdditionalService service, int dayCounts, int peopleCounts) {
            this.service = service;
            this.dayCounts = dayCounts;
            this.peopleCounts = peopleCounts;

            this.Price = this.CalculatePrice();
        }

        #endregion

        #region Methods

        private double CalculatePrice() {
            if (this.service == null) return 0;
            var price = this.service.UnitPrice;
            if (this.service.ServiceFor.HasFlag(ServiceFor.Day))
                price = price * this.dayCounts;
            if (this.service.ServiceFor.HasFlag(ServiceFor.Quantity))
                price = price * this.peopleCounts;
            return price;
        }

        #endregion

    }
}
